function bene() {
	var xmlhttpr;
	xmlhttpr = new XMLHttpRequest();
	xmlhttpr.onreadystatechange = function() {
		if(xmlhttpr.readyState == 4 && xmlhttpr.status == 200) {
			var json = JSON.parse(xmlhttpr.responseText)
			for(var i = 0; i < json.data.length; i++) {

				var li = document.createElement('li');
				var span = document.createElement('span');
				span.innerHTML = json.data[i].studentName;
				var span1 = document.createElement('span');
				span1.innerHTML = json.data[i].sex;
				var span2 = document.createElement('span');
				span2.innerHTML = json.data[i].age;

				li.appendChild(span);
				li.appendChild(span1);
				li.appendChild(span2);

				//ul
				document.querySelector('#list').appendChild(li);
			}
		}
	}
	xmlhttpr.open("GET", "http://localhost/ajaxApi/public/index.php/index/student/student", true);
	xmlhttpr.send();
}

bene();

//点击添加按钮
document.querySelector('#btn').onclick = function() {
	//姓名
	var ipt = document.querySelector('#inp').value;
	console.log(ipt);

	//性别
	var sex = document.querySelector('#sex').value;
	console.log(sex);

	//年龄
	var age = document.querySelector('#age').value;
	console.log(age);

	var xmlhttp;
	xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.querySelector("#list").innerHTML = "";
			bene();
		}
	}
    


	xmlhttp.open("GET", "http://localhost/ajaxApi/public/index.php/index/student/addstudent?studentName=" + ipt + "&sex= " + sex + "&age=" + age, true);
	xmlhttp.send();
}